package com.linciping.treeview;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private RecyclerView rvTree;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        rvTree = findViewById(R.id.rv_tree);

        List<AreaNode> countyNodeList = new ArrayList<>();
        countyNodeList.add(new AreaNode("000", "思明区", null));
        countyNodeList.add(new AreaNode("001", "集美区", null));
        countyNodeList.add(new AreaNode("002", "湖里区", null));
        List<AreaNode> cityNodeList = new ArrayList<>();
        cityNodeList.add(new AreaNode("00", "厦门市", countyNodeList));

        countyNodeList = new ArrayList<>();
        countyNodeList.add(new AreaNode("010", "鲤城区", null));
        countyNodeList.add(new AreaNode("011", "丰泽区", null));
        countyNodeList.add(new AreaNode("012", "洛江区", null));
        countyNodeList.add(new AreaNode("013", "晋江市", null));
        cityNodeList.add(new AreaNode("01", "泉州市", countyNodeList));

        countyNodeList = new ArrayList<>();
        countyNodeList.add(new AreaNode("020", "武平县", null));
        countyNodeList.add(new AreaNode("021", "上杭县", null));
        countyNodeList.add(new AreaNode("022", "新罗区", null));
        countyNodeList.add(new AreaNode("023", "永定区", null));
        cityNodeList.add(new AreaNode("02", "龙岩市", countyNodeList));

        List<AreaNode> provinceNodeList = new ArrayList<>();
        provinceNodeList.add(new AreaNode("0", "福建省", cityNodeList));

        cityNodeList = new ArrayList<>();
        countyNodeList = new ArrayList<>();
        countyNodeList.add(new AreaNode("100", "罗湖区", null));
        countyNodeList.add(new AreaNode("101", "福田区", null));
        countyNodeList.add(new AreaNode("102", "南山区", null));
        cityNodeList.add(new AreaNode("10", "深圳市", countyNodeList));

        countyNodeList = new ArrayList<>();
        countyNodeList.add(new AreaNode("110", "越秀区", null));
        countyNodeList.add(new AreaNode("111", "荔湾区", null));
        countyNodeList.add(new AreaNode("112", "海珠区", null));
        countyNodeList.add(new AreaNode("113", "天河区", null));
        cityNodeList.add(new AreaNode("11", "广州市", countyNodeList));

        countyNodeList = new ArrayList<>();
        countyNodeList.add(new AreaNode("120", "梅江区", null));
        countyNodeList.add(new AreaNode("121", "梅县区", null));
        countyNodeList.add(new AreaNode("122", "兴宁市", null));
        countyNodeList.add(new AreaNode("123", "蕉岭县", null));
        cityNodeList.add(new AreaNode("12", "梅州市", countyNodeList));

        provinceNodeList.add(new AreaNode("1", "广东省", cityNodeList));

        AreaAdapter areaAdapter = new AreaAdapter(this, provinceNodeList);
        rvTree.setLayoutManager(new LinearLayoutManager(this));
        rvTree.setAdapter(areaAdapter);
    }
}